<?php
/**
 * Created by PhpStorm.
 * User: JM003
 * Date: 2020/9/17
 * Time: 10:09
 */

namespace app\admin\controller;


use app\admin\model\OrganizationModel;

class Organization extends Base
{
    public function index(){
        return $this->fetch();
    }
    /**
     * 获取组织架构数据
     * @return mixed
     */
    public function getDeptList(){
        $model = new OrganizationModel();
        $list = $model->getDeptList();
        if($list){
            $ret['data'] = $list;
            $ret['code'] = 1;
            $ret['msg']  = '获取数据成功';
        }else{
            $ret['data'] = '';
            $ret['code'] = -1;
            $ret['msg']  = '获取数据为空';
        }
        return $ret;
    }

    /**
     * 获取员工列表
     */
    public function ajaxGetstaffList(){
        $model = new OrganizationModel();

        if(request()->isAjax()){
            $param = input('');
            $result = $model->getDeptStaffList($param);
            return $result;
        }
    }

    /**
     * 新增更新组织数据
     * @return mixed
     */
    public function ajaxAddUpdataDept(){
        $model = new OrganizationModel();

        if(request()->isAjax()){
            $param = input('');

            $result = $model->addUpdataDept($param);

            return $result;
        }
    }

    /**
     * 新增或者更新员工信息
     * @return mixed
     */
    public function ajaxAddUpdataStaff(){
        $model = new OrganizationModel();
        if(request()->isAjax()){
            $param = input('param.');
            if(!empty($param['password'])){
                $param['password'] = md5($param['password'].config('salt'));
            }else{
                unset($param['password']); //如果密码为空则移除字段，防止覆盖
            }
            $result = $model->addUpdataStaff($param);
            return $result;
        }
    }

}